﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RM2012Service.DataService;
using System.Data;
using System.Data.SqlClient;

namespace RM2012Service.DataAccess
{
    public class TablesDAO
    {
        DBConnection db;

        public TablesDAO()
        {
            db = new DBConnection();
        }

        public DataTable GetAllTables()
        {
            return db.ExecuteDataTable("GetAllTables", null);
        }

        public DataTable GetTableByArea(string areaId)
        {
            SqlParameter param = new SqlParameter("@AreaId", SqlDbType.VarChar, 6);
            param.Value = areaId;

            return db.ExecuteDataTable("GetTableByArea", param);
        }

        public DataTable GetTableById(string tableId)
        {
            SqlParameter param = new SqlParameter("@TablesId", SqlDbType.VarChar, 6);
            param.Value = tableId;

            return db.ExecuteDataTable("GetTableById", param);
        }

        public DataTable GetTableByState(int state)
        {
            SqlParameter param = new SqlParameter("@StateId", SqlDbType.Int);
            param.Value = state;

            return db.ExecuteDataTable("GetTableByState", param);
        }

        public DataSet GetTableByStateDataSet(int state)
        {
            SqlParameter param = new SqlParameter("@StateId", SqlDbType.Int);
            param.Value = state;

            return db.ExecuteDataSet("GetTableByStateFull", "Tables", param);
        }

        public int UpdateTableState(string tablesId, int stateId)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@TablesId", SqlDbType.VarChar, 6);
            param[0].Value = tablesId;

            param[1] = new SqlParameter("@StateId", SqlDbType.Int);
            param[1].Value = stateId;

            return db.ExecuteNoneQuery("UpdateTablesState", param);
        }
    }
}
